class Solution(object):
    @classmethod
    def countKDifference(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: int
        """
        ans = 0
        for i in range(len(nums)):
            for j in range(i, len(nums)):
                if abs(nums[i]-nums[j]) == k:
                    ans = ans+1

        return ans


if __name__ == '__main__':
    ans = Solution()
    print(ans.countKDifference([1, 2, 2, 1], 1))
